<%--
  Created by IntelliJ IDEA.
  User: Lanan
  Date: 2018/1/10 0010
  Time: 16:49
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<html>
<head>
    <%@ include file="/commons/basejs.jsp" %>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>余额提现记录</title>
</head>
<body>

<div class="easyui-layout" fit="true" >

    <%--///////////////////////////////////////  用户列表部分 ////////////////////////////////////////////--%>
    <div data-options="region:'west',split:true,border:false" title="用户列表" style="width:20%;">
        <table id="user_withdrawals_garid" class="easyui-datagrid"
               data-options="
		   		url:'${path }/userInfo/dataGrid.do',
		   		fit:true,
		   		idField:'id',
		   		sortName : 'id',
                sortOrder : 'asc',
		   		rownumbers:true,
		   		toolbar:'#user_withdrawals_tools',
		   		pagination:true,
		   		fitColumns:true,
		   		singleSelect:true,
		   		onClickRow:function(index, row){
		   		    getUserWithdrawalsApply(row.id);
		   		},
		   		">
            <thead>
            <th data-options="field:'username', align:'center'">用户名</th>
            <th data-options="field:'phone', align:'center'">手机</th>
            <th data-options="field:'email', align:'center'">邮箱</th>
            </thead>
        </table>

        <div id="user_withdrawals_tools">
            <form id="user_withdrawals_form">
                用户名：<input style="width: 90px" class="easyui-textbox" data-options="prompt:'请输入用户名'" type="text" id="withdrawalsUserName" name="usernameSearchWord"/>

                手机：<input style="width: 120px" class="easyui-numberbox" data-options="prompt:'请输入手机'" type="text" id="withdrawalsUserPhone" name="phoneSearchWord"/>
                <br/>
                邮箱：<input style="width: 120px" class="easyui-textbox" data-options="prompt:'请输入邮箱'" type="text" id="withdrawalsUserEmail" name="emailSearchWord"/>

                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="searchWithdrawalsUser()">搜索</a>
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="resetWithdrawalsUserSearch()">重置</a>
            </form>
        </div>
    </div>
    <script type="text/javascript">

        function getUserWithdrawalsApply(id) {
            var select = $("#withdrawals_garid").datagrid("getSelected");
            if(select != null){
                $('#withdrawals_garid').datagrid('clearSelections');
            }
            var queryParams = {};
            queryParams.userId = id;
            var options = $("#withdrawals_garid").datagrid('getPager').data("pagination").options;
            options.pageNumber = 1;
            //重新加载
            $("#withdrawals_garid").datagrid('options').queryParams = queryParams;
            $("#withdrawals_garid").datagrid('reload');
        }

        function searchWithdrawalsUser() {
            var queryParams = {};
            queryParams.usernameSearchWord = $("#withdrawalsUserName").val();
            queryParams.phoneSearchWord =$("#withdrawalsUserPhone").val();
            queryParams.emailSearchWord =$("#withdrawalsUserEmail").val();
            var options = $("#user_withdrawals_garid").datagrid('getPager').data("pagination").options;
            options.pageNumber = 1;
            //重新加载
            $("#user_withdrawals_garid").datagrid('options').queryParams = queryParams;
            $("#user_withdrawals_garid").datagrid('reload');
        }

        function resetWithdrawalsUserSearch() {
            $("#user_withdrawals_form").form("clear");
        }
    </script>



    <%--///////////////////////////////////////  提现记录 ////////////////////////////////////////////--%>
    <div data-options="region:'center',split:true,border:false" title="用户余额提现记录" style="width:50%;">
        <table id="withdrawals_garid" class="easyui-datagrid"
               data-options="
		   		url:'${path }/user/withdrawals/list.do',
		   		fit:true,
		   		idField:'id',
		   		sortName : 'id',
                sortOrder : 'asc',
		   		rownumbers:true,
		   		toolbar:'#withdrawals_tools',
		   		pagination:true,
		   		fitColumns:true,
		   		singleSelect:true,
		   		onClickRow:function(index, row){
		   		    getUserWithdrawalsDetailApply(row.id);
		   		},
		   		">
            <thead>
            <th data-options="field:'id', align:'center', checkbox:true">ID</th>
            <th data-options="field:'accountName', align:'center'">账户姓名</th>
            <th data-options="field:'accountPhone', align:'center'">手机号</th>
            <th data-options="field:'extractMoney', align:'center'">金额</th>
            <th data-options="field:'wechatAccount', align:'center'">微信账号</th>
            <th data-options="field:'aliAccount', align:'center'">支付宝账号</th>
            <th data-options="field:'bankAccount', align:'center'">银行账号</th>
            <th data-options="field:'bankName', align:'center'">银行名称</th>
            <th data-options="field:'bankOpening', align:'center'">开户行信息</th>
            <th data-options="field:'accountType', align:'center', formatter:formatWithdrawalsAccountType">账户类型</th>
            <th data-options="field:'type', align:'center', formatter:formatWithdrawalsType">提现类型</th>
            <th data-options="field:'typeName', align:'center'">提现类型</th>
            <th data-options="field:'createTime', align:'center', formatter:formatDatebox">申请时间</th>
            <th data-options="field:'updateTime', align:'center', formatter:formatDatebox">处理时间</th>
            </thead>
        </table>
        <div id="withdrawals_tools">
            <form id="withdrawals_search_form">
                <label>账户类型:</label>
                <select id="withdrawalsAccountType" name="accountType" class="easyui-combobox" data-options="width:'73px', editable:false, panelHeight:'auto'">
                    <option value="">全部</option>
                    <option value="0">银行卡</option>
                    <option value="1">支付宝</option>
                    <option value="2">微信</option>
                </select>
                <label>提现类型:</label>
                <select id="withdrawalsType" name="type" class="easyui-combobox" data-options="width:'108px', editable:false, panelHeight:'auto'">
                    <option value="">全部</option>
                    <option value="0">申请提现</option>
                    <option value="1">拒绝提现</option>
                    <option value="2">提现审核通过</option>
                    <option value="3">提现完成</option>
                </select>
                <label>开始时间</label>
                <input id="searchWithdrawalsStartTemp" name="searchStartTemp" type="text" class="easyui-datebox">
                <label>结束时间</label>
                <input id="searchWithdrawalsEndTemp" name="searchEndTemp" type="text" class="easyui-datebox">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="searchUserWithdrawals()">搜索</a>
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-clear'" onclick="searchUserWithdrawalsReset()">重置</a>
                <br/>
            </form>
            <div style="padding:5px;background:#ffffff;width:100%;border:1px solid #ccc;text-align: center;">
                <label>审核:&nbsp;&nbsp;</label>
                <shiro:hasPermission name="/user/coupon/delete.do">
                    <a href="#" plain="true" class="easyui-linkbutton" data-options="iconCls:'icon-no'" onclick="checkUserWithdrawals(0)"><span style="color:red">拒绝</span></a>
                    &nbsp;&nbsp;
                </shiro:hasPermission>
                <shiro:hasPermission name="/user/coupon/delete.do">
                    <a href="#" plain="true" class="easyui-linkbutton" data-options="iconCls:'icon-tip'" onclick="checkUserWithdrawals(1)"><span style="color:#ffcc00">通过</span></a>
                    &nbsp;&nbsp;
                </shiro:hasPermission>
                <shiro:hasPermission name="/user/coupon/delete.do">
                    <a href="#" plain="true" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="checkUserWithdrawals(2)"><span style="color:green">完成</span></a>
                </shiro:hasPermission>
            </div>
        </div>
        <div class="easyui-dialog" id="no_withdrawals_remark" data-options="closed:true,modal:true,width:300,height:200">
            <form id="no_withdrawals_remark_form">
                <input hidden name="id" id="withdrawals_id"/>
                <textarea id="insert_article_intro" name="remark" class="easyui-validatebox" data-options="missingMessage:'请输入拒绝缘由',required:true" style="margin: 0px; width: 100%;height:73%;"></textarea>
                <div  data-options="region:'south',border:false" style="height: 24px; padding-top: 8px;text-align: center" >
                    <a  class="easyui-linkbutton" icon="icon-save" onclick="submitNoUserWithdrawals()">保存</a>
                    <a  class="easyui-linkbutton" icon="icon-cancel" onclick="$('#no_withdrawals_remark').dialog('close');" >取消</a>
                </div>
            </form>
        </div>
        <script type="text/javascript">

            // 审核处理
            function checkUserWithdrawals(type) {
                var select = $('#withdrawals_garid').datagrid('getSelected');
                if (select == null) {
                    $.messager.alert("提示","请选择要操作的提现申请！","info");
                    return;
                }
                if (select.type == 3) {
                    $.messager.alert("提示","该提现申请已完成提现, 操作失败！","info");
                    return;
                }
                if (select.type == 2) {
                    if (type != 2) {
                        $.messager.alert("提示","该提现申请已通过提现, 操作失败！","info");
                        return;
                    }
                }
                if (select.type == 1) {
                    $.messager.alert("提示","该提现申请已被拒绝, 操作失败！","info");
                    return;
                }
                if (type == 2 && select.type == 0) {
                    $.messager.alert("提示","该提现申请尚未通过审核, 操作失败！","info");
                    return;
                }
                switch (type){
                    // 拒绝
                    case 0: {
                        <%--editUserIthdrawls("你确定要拒绝该提现申请?", "${path }/user/withdrawals/check/no.do", select.id)--%>
                        editNoUserIthdrawls(select.id);
                    } break;
                    // 通过
                    case 1: {
                        editUserIthdrawls("你确定要通过该提现申请?", "/user/withdrawals/check/yes.do", select.id)
                    } break;
                    // 完成
                    case 2: {
                        editUserIthdrawls("你确定已完成该提现申请?", "/user/withdrawals/check/finish.do", select.id)
                    } break;
                }
            }

            // 拒绝
            function editNoUserIthdrawls(id) {
                $("#no_withdrawals_remark_form").form('clear');
                $("#no_withdrawals_remark").dialog({title: "你将拒绝该条用户提现申请! 请填写拒绝原因"});
                $("#no_withdrawals_remark").dialog("open");
                $("#withdrawals_id").val(id);
            }

            function submitNoUserWithdrawals() {
                $.messager.progress();
                $("#no_withdrawals_remark_form").form("submit", {
                    url:'${path }/user/withdrawals/check/no.do',
                    onSubmit:function(){
                        var valid = $(this).form("validate");
                        if (!valid) {
                            $.messager.progress("close");
                        }
                        return valid;
                    },
                    success:function(data){
                        data=$.parseJSON(data);
                        console.log(data)
                        $.messager.progress("close");
                        $("#no_withdrawals_remark").dialog("close");

                        if(data.success){
                            $.messager.show({
                                title:"操作成功",
                                msg:data.msg,
                                timeout:600,
                                style:"left:30%;top:10%",
                                showType:"fade"
                            });
                            $("#withdrawals_garid").datagrid("reload");
                            $('#withdrawals_garid').datagrid('clearSelections');
                            $("#withdrawals_detail_garid").datagrid('reload')
                        } else {
                            $.messager.alert("操作失败", data.msg,"error");
                        }
                    },
                    error:function () {
                        $.messager.progress("close");
                        $.messager.alert("操作失败", "服务器连接失败!","error");
                    }
                })
            }

            function editUserIthdrawls(alertStr, url, id) {
                $.messager.confirm("确认",alertStr, function(yes) {
                    if (yes) {
                        editRquest(url, {id:id});
                    }
                })
            }

            function editRquest(url, data) {
                $.messager.progress();
                $.ajax({
                    url: url,
                    type: 'post',
                    data: data,
                    dataType:'json',
                    success:function (data) {
                        $.messager.progress("close");
                        if (data.success) {
                            $.messager.show({
                                title:"操作成功",
                                msg:data.msg,
                                timeout:600,
                                style:"left:30%;top:10%",
                                showType:"fade"
                            });
                            $("#withdrawals_garid").datagrid('clearSelections');
                            $("#withdrawals_garid").datagrid('reload')
                            $("#withdrawals_detail_garid").datagrid('reload')
                        } else {
                            $.messager.alert("操作失败", data.msg, "error");
                        }
                    },
                    error:function () {
                        $.messager.progress("close");
                        $.messager.progress("close");
                        $.messager.alert("操作失败", "服务器连接失败!","error");
                    }
                })
            }


            function getUserWithdrawalsDetailApply(id) {
                var select = $("#withdrawals_detail_garid").datagrid("getSelected");
                if(select != null){
                    $('#withdrawals_detail_garid').datagrid('clearSelections');
                }
                var queryParams = {};
                queryParams.extractRecordId = id;
                var options = $("#withdrawals_detail_garid").datagrid('getPager').data("pagination").options;
                options.pageNumber = 1;
                //重新加载
                $("#withdrawals_detail_garid").datagrid('options').queryParams = queryParams;
                $("#withdrawals_detail_garid").datagrid('reload');
            }

            function searchUserWithdrawals() {
                var queryParams = {};
                queryParams.accountType = $("#withdrawalsAccountType").combobox('getValue');
                queryParams.type = $("#withdrawalsType").combobox('getValue');
                var searchStartTemp = $("#searchWithdrawalsStartTemp").datebox("getValue");
                var searchEndTemp = $("#searchWithdrawalsEndTemp").datebox("getValue");
                if (searchEndTemp != null || searchEndTemp == null) {
                    if (searchEndTemp != null && searchEndTemp != "" && !checkDate(searchEndTemp, "结束时间格式错误")) {
                        return;
                    }
                    if (searchStartTemp != null && searchStartTemp != "" && !checkDate(searchStartTemp, "开始时间格式错误")) {
                        return;
                    }
                    if (searchEndTemp != null && searchEndTemp != "" && searchEndTemp < searchStartTemp) {
                        $.messager.alert("提示","结束时间不能小于开始时间！","info");
                        return;
                    }
                    queryParams.searchStartTemp = searchStartTemp;
                    queryParams.searchEndTemp = searchEndTemp;
                }
                $("#withdrawals_garid").datagrid('options').queryParams = queryParams;
                $("#withdrawals_garid").datagrid('getPager').data("pagination").options.pageNumber = 1;
                $("#withdrawals_garid").datagrid('reload');
                $("#withdrawals_detail_garid").datagrid('reload')
            }

            function searchUserWithdrawalsReset() {
                $("#withdrawals_search_form").form("clear");
            }

        </script>
    </div>


    <%--///////////////////////////////////////  提现记录明细 ////////////////////////////////////////////--%>
    <div data-options="region:'east',split:true,border:false" title="用户余额提现记录明细" style="width:30%;">
        <table id="withdrawals_detail_garid" class="easyui-datagrid"
               data-options="
            url:'${path }/user/withdrawals/detail/list.do',
            fit:true,
            idField:'id',
            sortName : 'id',
            sortOrder : 'asc',
            rownumbers:true,
            toolbar:'#withdrawals_detail_tools',
            pagination:true,
            fitColumns:true,
            singleSelect:true,
            ">
            <thead>
            <th data-options="field:'id', align:'center', checkbox:true">ID</th>
            <th data-options="field:'remark', align:'center'">操作备注</th>
            <th data-options="field:'opUsername', align:'center'">操作人用户名或手机号</th>
            <th data-options="field:'type', align:'center', formatter:formatWithdrawalsType">提现类型</th>
            <th data-options="field:'typeName', align:'center'">提现类型</th>
            <th data-options="field:'createTime', align:'center', formatter:formatDatebox">处理时间</th>
            <th data-options="field:'updateTime', align:'center', formatter:formatDatebox">更新时间</th>
            </thead>
        </table>
    </div>
</div>

<script type="text/javascript">
    function formatWithdrawalsType(value) {
        if(value == "0") {
            return  '<span style="color:steelblue">' + '申请提现' + '</span>';
        } else if(value == "1") {
            return  '<span style="color:red">' + '拒绝提现' + '</span>';
        } else if (value == "2") {
            return  '<span style="color:greenyellow">' + '提现审核通过' + '</span>';
        }  else if (value == "3") {
            return  '<span style="color:green">' + '提现完成' + '</span>';
        }
    }

    function formatWithdrawalsAccountType(value) {
        if(value == "2") {
            return  '<span style="color:lightgreen">' + '微信' + '</span>';
        } else if(value == "1") {
            return  '<span style="color:deepskyblue">' + '支付宝' + '</span>';
        } else if (value == "0") {
            return  '<span style="color:slateblue">' + '银行卡' + '</span>';
        }
    }
</script>

</body>
</html>
